﻿<?php 
include_once 'public/DB_Oracle.php';
include_once 'public/page/page.class.php';
$DBsql = new DB_Oracle ();
//查询所以警员
if(isset($_GET['option'])){
if($_GET['option']=="del"){
	$sql="delete from dep_vehicle dp where dp.vehicle_index in (".$_GET['id'].")";
	if($DBsql->query($sql))
	echo "<script language='javascript'>alert('删除成功');</script>";
	else
	echo "<script language='javascript'>alert('没有删除成功');</script>";
	}
if($_GET['option']=="change"){
	$sql="select count(*) count from dep_vehicle t where (t.license_plate='".$_GET['char_card']."' or t.device_id='".$_GET['charid']."') and t.vehicle_index<>".$_GET['charnum']."";
	$data=$DBsql->fetch_all_array($sql);
	if($data[0]['COUNT']>0){
		echo "<script language='javascript'>alert('没有修改成功您输入的车牌号或者设备编号已经存在');</script>";
		}else{
	$sql="select * from dep_vehicle_type t where t.vehicle_type_name='".$_GET['chartype']."'";
	$data=$DBsql->fetch_all_array($sql);
$sql="update dep_vehicle dp
          set dp.vehicle_index=".$_GET['charnum'].",
		  dp.vehicle_type_index=".$data[0]['VEHICLE_TYPE_INDEX'].",
		  dp.vehicle_name='".$_GET['charname']."',
		  dp.device_id='".$_GET['charid']."',
		  dp.license_plate='".$_GET['char_card']."',
		  dp.sim='".$_GET['sim']."',
		  dp.department_index='".$_GET['charuint']."' 
		  where dp.vehicle_index=".$_GET['charnum']."";
	if($DBsql->query($sql))
	echo "<script language='javascript'>alert('修改成功');</script>";
	else
	echo "<script language='javascript'>alert('没有修改成功');</script>";}
	
	}

if($_GET['option']=="add"){
	$sql="select count(*) count from dep_vehicle t where t.license_plate='".$_GET['char_card']."' or t.device_id='".$_GET['charid']."'";
	$data=$DBsql->fetch_all_array($sql);
	if($data[0]['COUNT']>0){
		echo "<script language='javascript'>alert('没有添加成功您输入的车牌号或者设备编号已经存在');</script>";
		}else{
$sql="insert into dep_vehicle(vehicle_index,vehicle_type_index,vehicle_name,device_id,license_plate,department_index,sim)values
(dep_vehicle_seq.nextval,".$_GET['chartype'].",'".$_GET['charname']."','".$_GET['charid']."','".$_GET['char_card']."','".$_GET['charuint']."','".$_GET['sim']."')";
	if($DBsql->query($sql))
	echo "<script language='javascript'>alert('添加成功');</script>";
	else
	echo "<script language='javascript'>alert('没有添加成功');</script>";}
	
	}}


$sql="select * from dep_vehicle";
$rows=$DBsql->fetch_all_array($sql);
//查询所有的派出所
$sql="select dd.department_index, dd.department_name
		  from dep_department dd
		 order by dd.department_index";
$dedp=$DBsql->fetch_all_array($sql);


if(empty($_GET['departmentID'])){
		$sql="select dp.vehicle_index from dep_vehicle dp";
	$rows=$DBsql->fetch_all_array($sql);
$pageSize = 15;
$total=count($rows)== 0 ? 1 : count($rows);
//第一个0显示数字  第二个1显示概况 第三个显示下拉 第四个显示数字数量
pageft($total, $pageSize, 1, 1, 1, 5);
$displaypg+=$firstcount;
$sql="select *
	  from (select rownum r,t.vehicle_index,t.sim,t2.vehicle_type_name,t.vehicle_name,t.device_id,t.license_plate,t1.department_name from dep_vehicle t,dep_department t1,dep_vehicle_type t2 where t.department_index=t1.department_index and t.vehicle_type_index=t2.vehicle_type_index order by t.vehicle_index asc) c
	 where c.r > $firstcount
	   and c.r <= $displaypg";
$rows=$DBsql->fetch_all_array($sql);}else{
	$depID=$_GET['departmentID'];
			$sql="select dp.vehicle_index from dep_vehicle dp where dp.department_index=$depID";
	$rows=$DBsql->fetch_all_array($sql);
$pageSize = 15;
$total=count($rows)== 0 ? 1 : count($rows);
//第一个0显示数字  第二个1显示概况 第三个显示下拉 第四个显示数字数量
pageft($total, $pageSize, 1, 1, 1, 5);
$displaypg+=$firstcount;
$sql="select *
	  from (select rownum r,t.vehicle_index,t.sim,t2.vehicle_type_name,t.vehicle_name,t.device_id,t.license_plate,t1.department_name from dep_vehicle t,dep_department t1,dep_vehicle_type t2 where t.department_index=t1.department_index and t.department_index=$depID and  t.vehicle_type_index=t2.vehicle_type_index order by t.vehicle_index asc) c
	 where c.r > $firstcount
	   and c.r <= $displaypg";
$rows=$DBsql->fetch_all_array($sql);
	
	}
?>
<link href="css/style.css" rel="stylesheet" type="text/css" />
<link href="css/validform.css" rel="stylesheet" type="text/css" />
<link href="public/page/css/css.css" rel="stylesheet" type="text/css" />
<script language="javascript" type="text/javascript" src="js/jquery.js"></script>
<script language="javascript" type="text/javascript" src="js/public.js"></script> 
<script language="javascript">
function department(str){
	var url="cheliang.php?"+encodeURI("dep="+str);
	window.location=url;  
	}
function editRow(rowId){
	var obj=document.getElementById(rowId).getElementsByTagName('td');
	 for(var i=0;i<4;++i){
		document.getElementById("charmoto_"+i).value=obj.item(i+1).innerHTML;
		 }
		 document.getElementById("charmoto_4").value=obj.item(6).innerHTML;
		 for(var i=0;i<document.getElementById('charmoto_5').options.length;++i){
			if(document.getElementById('charmoto_5').options[i].text==obj.item(7).innerHTML){
			document.getElementById("charmoto_5").options[i].selected=true	
				} 
			 }
		 document.getElementById("charmoto_10").value=obj.item(5).innerHTML;	POPdiv('UPdiv');
	}
function CheckAll(obj){var chebox=document.getElementsByName('checkbox_id');if(obj.checked==true){
for(var i=0;i<chebox.length;++i){chebox.item(i).checked=true;}}else{for(var i=0;i<chebox.length;++i){chebox.item(i).checked=false;}}
}
function delChecked(){
	var chebox=document.getElementsByName('checkbox_id');
	var chebox_value="";
	for(var i=0;i<chebox.length;++i){
		if(chebox.item(i).checked==true){
			chebox_value+=chebox.item(i).value+",";
			}}
    if(chebox_value==""){
		alert("您没有选择东西");
	return 0;
		}
if(confirm("确定删除？")){
	var url="cheliang.php?"+encodeURI("option=del&id="+chebox_value.substr(0,chebox_value.length-1));
	window.location=url; 
	}	}
function delRow(policechar_id){
if(confirm("确定删除？")){
	var url="cheliang.php?"+encodeURI("option=del&id="+policechar_id);
	window.location=url; 
	}
	}
function select_value(obj){
	if(obj.value=='0'){
	obj.parentNode.parentNode.getElementsByTagName("span").item(0).className="Validform_wrong Validform_checktip";
	obj.parentNode.parentNode.getElementsByTagName("span").item(0).innerHTML="没有输入";
	}
	else{obj.parentNode.parentNode.getElementsByTagName("span").item(0).className="Validform_checktip Validform_right";
	obj.parentNode.parentNode.getElementsByTagName("span").item(0).innerHTML="输入正确";}
	
	}
function text_value(obj){
	if(obj.value==""){
		obj.parentNode.parentNode.getElementsByTagName("span").item(0).className="Validform_wrong Validform_checktip";
	obj.parentNode.parentNode.getElementsByTagName("span").item(0).innerHTML="没有输入";		
		}else{obj.parentNode.parentNode.getElementsByTagName("span").item(0).className="Validform_checktip Validform_right";
	obj.parentNode.parentNode.getElementsByTagName("span").item(0).innerHTML="输入正确";}
	}
function UP(){
		for(var i=0;i<5;++i){
           if(document.getElementById("charmoto_"+i).value==""){
			   alert("请检查你输入是否正确");
			   return false;
			   }}
			   if(document.getElementById("charmoto_10").value==""){
			   alert("请检查你输入是否正确");
			   return false;
			   }
			   			  var  re = /^\d{11}$/
			  if(!re.test(document.getElementById("charmoto_10").value)){
			   alert("请检查你输入是否正确");
			   return false;
			   }
			  if(document.getElementById("charmoto_5").value=='0'){
				  alert("请检查你输入是否正确");
			   return false;
				  }
var str_arr=[document.getElementById("charmoto_0").value,document.getElementById("charmoto_1").value,document.getElementById("charmoto_2").value,document.getElementById("charmoto_3").value,document.getElementById("charmoto_4").value,document.getElementById("charmoto_5").value,document.getElementById("charmoto_10").value];
	var url="cheliang.php?"+encodeURI("option=change&charnum="+str_arr[0]+"&chartype="+str_arr[1]+"&charname="+str_arr[2]+"&charid="+str_arr[3]+"&char_card="+str_arr[4]+"&charuint="+str_arr[5]+"&sim="+str_arr[6]);
	window.location=url;  
		}
function ADD(){
		for(var i=0;i<5;++i){
           if(document.getElementById("add_"+i).value==""){
			   alert("请检查你输入是否正确");
			   return false;
			   }}
			   if(document.getElementById("add_10").value==""){
			   alert("请检查你输入是否正确");
			   return false;
			   }
			  var  re = /^\d{11}$/
			  if(!re.test(document.getElementById("add_10").value)){
			   alert("请检查你输入是否正确");
			   return false;
			   }
			  if(document.getElementById("add_0").value=='0'){
				  alert("请检查你输入是否正确");
			   return false;
				  }
			
			  if(document.getElementById("add_4").value=='0'){
				  alert("请检查你输入是否正确");
			   return false;
				  }
var str_arr=[document.getElementById("add_0").value,document.getElementById("add_1").value,document.getElementById("add_2").value,document.getElementById("add_3").value,document.getElementById("add_4").value,document.getElementById("add_10").value];
	var url="cheliang.php?"+encodeURI("option=add&chartype="+str_arr[0]+"&charname="+str_arr[1]+"&charid="+str_arr[2]+"&char_card="+str_arr[3]+"&charuint="+str_arr[4]+"&sim="+str_arr[5]);
	window.location=url;  
		}
document.ondblclick = function(){
	//$("#selectID").val('');
	POPdiv('selectLocation');
};
function groupSelect(){
	var policeID=$("#selectID").val();
	$('#departmentID').val(policeID);
	$('#Location').submit();
}
</script>
 
<!--管理列表开始-->
<div class="manageTab" style="margin-top:0px;">
  <table width="100%" border="0" cellspacing="0" cellpadding="0" align="center" class="usrTab">
    <tr>
      <td width="8" height="25"><img src="images/user_01.jpg" height="25" width="8" /></td>
      <td style="background:#3980b2;" valign="middle" height="16" ><div class="use_righgDiv"><span>
          <input type="checkbox" id="checkall" name="" value="" onclick="CheckAll(this)" />
          全选</span><span><img src="images/001.gif" height="14" width="14" /><a href="javascript:void(null)" onclick="javascript:POPdiv('POPdiv')">新增</a></span><span><img src="images/114.gif" height="14" width="14" /><a onclick="delChecked()" href="javascript:void(null)">批量删除</a></span></div>
        <div class="use_leftDiv">
          <table width="100%" border="0" cellspacing="0" cellpadding="0">
            <tr>
              <td  width="22"><img src="images/311.gif" height="16" width="16" /></td>
              <td align="left"><span class="tdTit">车辆管理列表</span></td>
            </tr>
          </table>
        </div></td>
      <td width="8" height="25"><img src="images/user_02.gif" height="25" width="8" /></td>
    </tr>
    <tr>
      <td style="background:#3980b2;" >&nbsp;</td>
      <td><table width="100%" border="0" cellspacing="1" cellpadding="0" align="center" class="usrList" id="List">
          <tr>
            <td  class="td90b2">选择</td>
            <td  class="td90b2">车辆编号</td>
            <td  class="td90b2">类型</td>
            <td  class="td90b2">车辆名字</td>
             <td  class="td90b2">车辆持有设备编号</td>
             <td  class="td90b2">手机号</td>
            <td  class="td90b2">车牌号</td>
            <td  class="td90b2">所属单位</td>
            <td  class="td90b2">编辑</td>
            <td  class="td90b2">删除用户</td>
          </tr>
          <?php if(count($rows)!=0){
          		foreach ($rows as $ros){
          	?>
	          <tr id="<?php echo $ros['VEHICLE_INDEX'];?>">
	            <td class="tdfff"><input type='checkbox' name="checkbox_id" class="STYLE2" value="<?php echo $ros['VEHICLE_INDEX'];?>" /></td>
	            <td class="tdfff"><?php echo $ros['VEHICLE_INDEX'];?></td>
	            <td class="tdfff"><?php echo $ros['VEHICLE_TYPE_NAME'];?></td>
	            <td class="tdfff"><?php echo $ros['VEHICLE_NAME'];?></td>
	            <td class="tdfff"><?php echo $ros['DEVICE_ID'];?></td>
                <td class="tdfff"><?php echo $ros['SIM'];?></td>
	            <td class="tdfff"><?php echo $ros['LICENSE_PLATE'];?></td>
	            <td class="tdfff" onclick="department('<?php echo $ros['DEPARTMENT_NAME'];?>')"><?php echo $ros['DEPARTMENT_NAME'];?></td>
	            <td class="tdfff"><div align="center"><img src="images/037.gif" width="9" height="9" /><span class="STYLE1"> [</span><a href="javascript:void(null)" onclick="editRow('<?php echo $ros['VEHICLE_INDEX'];?>')">编辑</a><span class="STYLE1">]</span></div></td>
	            <td class="tdfff"><div align="center"><img src="images/010.gif" width="9" height="9" /><span class="STYLE1"> [</span><a href="javascript:void(null)" onclick="delRow('<?php echo $ros['VEHICLE_INDEX'];?>')">删除</a><span class="STYLE1">]</span></div></td>
	          </tr>
          <?php }}else{echo "<tr><td colspan='5' class='tdfff'><font color='#FF0000'>暂无数据！</font></td></tr>";}?>
          <tr>
            <td colspan="10" class="tdfff">&nbsp;</td>
          </tr>
        </table></td>
      <td style="background:#3980b2;">&nbsp;</td>
    </tr>
    <tr>
      <td height="24" width="8"><img src="images/user_03.gif" height="24" width="8" /></td>
      <td style="background:#3980b2;"><div class="green-black"><?php echo $pagenav;?>
        </div></td>
      <td height="24" width="8"><img src="images/user_04.gif" height="24" width="8" /></td>
    </tr>
  </table>
</div>
<!--管理列表结束-->
      
<!--弹出层开始-->
<div id="POPdiv" class="POPdiv">
  <div class="POPdiv_top"><a href="javascript:void(null)" onclick="ClosePOPdiv('POPdiv')"><img src="images/ico_close.jpg" alt="关闭" /></a>车辆管理</div>
  <div class="POPdiv_content">
    <form action="" method="post">
     <table border="0" cellpadding="5" cellspacing="0">
                <tr>
			      <td width="80"><label for="userNameUp">车辆类型：</label></td>
			      <td><select id="add_0" onchange="select_value(this)">
          <option value="0">选择车辆类型</option>
          <option value="1">警车</option>
          <option value="2">警用摩托</option>
        </select></td>
			      <td><span class="Validform_checktip">请选择车辆类型</span></td>
			    </tr>
                <tr>
			      <td width="80"><label for="userNameUp">车辆名字：</label></td>
			      <td><input type="text" id="add_1" onblur="text_value(this)"/></td>
			      <td><span class="Validform_checktip">请输入车辆名字</span></td>
			    </tr>
			    <tr>
			      <td width="80"><label for="userNameUp">设备编号：</label></td>
			      <td><input type="text" id="add_2" onblur="text_value(this)" /></td>
			      <td><span class="Validform_checktip">请输入设备编号</span></td>
			    </tr>
                <tr>
			      <td width="80"><label for="userSimUp">手机号：</label></td>
			      <td><input type="text" id="add_10" /></td>
			      <td><span class="Validform_checktip">手机号11位数字</span></td>
			    </tr>
                <tr>
			      <td width="80"><label for="userNameUp">车牌号：</label></td>
			      <td><input type="text" id="add_3" onblur="text_value(this)" /></td>
			      <td><span class="Validform_checktip">请输入车牌号</span></td>
			    </tr>
			    <tr>
			      <td width="80"><label for="workUp">所在单位：</label></td>
			      <td><select id="add_4" datatype='select' onchange="select_value(this)">
			          <option value="0">选择单位</option>
			           <?php 
			          	foreach ($dedp as $row){
			          		echo "<option value='".$row['DEPARTMENT_INDEX']."'>".$row['DEPARTMENT_NAME']."</option>";
			          	}
			          ?>
			        </select></td>
			      <td><span class="Validform_checktip"></span></td>
			    </tr>
			    <tr>
			      <td colspan="3"><input id="up" type="button" class="btnbg" onclick="ADD()" value="添加车辆信息" style="width:100px; margin-left:80px; color:#FFF" /></td>
			    </tr>
			  </table>
    </form>
  </div>
</div>
<!--弹出层结束-->
<!--弹出层修改车辆数据开始-->
      <div id="UPdiv" class="POPdiv">
        <div class="POPdiv_top"><a href="javascript:void(null)" onclick="ClosePOPdiv('UPdiv')"><img src="images/ico_close.jpg" alt="关闭" /></a>修改警员信息</div>
        <div class="POPdiv_content">
          <form class="adduser" id="upuser" action="" method="post">
			  <table border="0" cellpadding="5" cellspacing="0">
			    <tr>
			      <td width="80"><label for="userNumUp">车辆编号：</label></td>
			      <td><input type="text" disabled="true" id="charmoto_0" name='charmoto_0'/></td>
			      <td><span class="Validform_checktip Validform_right">不能输入</span></td>
			    </tr>
                <tr>
			      <td width="80"><label for="userNameUp">车辆类型：</label></td>
			      <td><input type="text" disabled="true" id="charmoto_1" name='charmoto_1'/></td>
			      <td><span class="Validform_checktip Validform_right">不能输入</span></td>
			    </tr>
                <tr>
			      <td width="80"><label for="userNameUp">车辆名字：</label></td>
			      <td><input type="text" id="charmoto_2" name="charmoto_2" onblur="text_value(this)"/></td>
			      <td><span class="Validform_checktip">请输入车辆名字</span></td>
			    </tr>
			    <tr>
			      <td width="80"><label for="userNameUp">设备编号：</label></td>
			      <td><input type="text" id="charmoto_3" name="charmoto_3" onblur="text_value(this)" /></td>
			      <td><span class="Validform_checktip">请输入设备编号</span></td>
			    </tr>			    <tr>
			      <td width="80"><label for="userNameUp">手机号：</label></td>
			      <td><input type="text" id="charmoto_10" name="charmoto_3" onblur="text_value(this)" /></td>
			      <td><span class="Validform_checktip">手机号11位数字</span></td>
			    </tr>
                <tr>
			      <td width="80"><label for="userNameUp">车牌号：</label></td>
			      <td><input type="text" id="charmoto_4" name="charmoto_4" onblur="text_value(this)" /></td>
			      <td><span class="Validform_checktip">请输入车牌号</span></td>
			    </tr>
			    <tr>
			      <td width="80"><label for="workUp">所在单位：</label></td>
			      <td><select  id="charmoto_5" name="charmoto_5"  datatype='select' onchange="select_value(this)">
			          <option value="0">选择单位</option>
			           <?php 
			          	foreach ($dedp as $row){
			          		echo "<option value='".$row['DEPARTMENT_INDEX']."'>".$row['DEPARTMENT_NAME']."</option>";
			          	}
			          ?>
			        </select></td>
			      <td><span class="Validform_checktip"></span></td>
			    </tr>
			    <tr>
			      <td colspan="3"><input id="up" type="button" class="btnbg" onclick="UP()" value="修改车辆信息" style="width:100px; margin-left:80px; color:#FFF" /></td>
			    </tr>
			  </table>
		  </form>
        </div>
      </div>
<!--弹出层修改车辆数据层结束-->
<!--弹出层选择派出所开始-->
<div id="selectLocation" class="POPdiv">
	 <div class="POPdiv_top"><a href="javascript:void(null)" onclick="ClosePOPdiv('selectLocation')"><img src="images/ico_close.jpg" alt="关闭" /></a>分组查看</div>
        <div class="POPdiv_content">
        	<form id="Location" action="cheliang.php" method="get">
	        	 <table border="0" cellpadding="5" cellspacing="0">
				    <tr>
				      <td width="80"><label for="selectID">选择派出所</label></td>
				      <td>
					  	<select id="selectID" name="selectID" onchange="groupSelect()">
							<option value="">全部</option>
							 <?php 
					          	foreach ($dedp as $row){
					         ?>
					         	<option <?php if(isset($_GET['departmentID'])){if($_GET['departmentID']==$row['DEPARTMENT_INDEX']){echo 'selected=selected';}}?> value="<?php echo $row['DEPARTMENT_INDEX'];?>"><?php echo $row['DEPARTMENT_NAME'];?></option>	
					         <?php
					          	}
					         ?>
						</select>
					  </td>
				      <td><input type="hidden" id="departmentID" name="departmentID" value=""></td>
				    </tr>
				 </table>
			 </form>
		</div>
</div>
<!--弹出层选择派出所结束-->